package com.longyiqun.cm.mapper;

import com.longyiqun.cm.domain.ServerEntity;
import com.longyiqun.cm.domain.TestCaseEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Controller;

import java.util.List;
@Controller
@Mapper
public interface CasesMapper {

    @Select("SELECT * from test_case_entity")
    List<TestCaseEntity> findAllCases();

    @Select("SELECT * from test_case_entity WHERE ID = #{id}")
    TestCaseEntity findOne(@Param("id") String id);

    @Update("UPDATE test_case_entity SET name=#{name}, url=#{url}, body=#{body}, module =#{module}, chinese=#{chinese}, shouldbe=#{shouldbe}, status=#{status}, remark=#{remark}, method=#{method}, signature=#{signature} WHERE id =#{id}")
    int updateCases(TestCaseEntity testCaseEntity);

    @Insert("INSERT into test_case_entity (name, url, body, module, chinese, shouldbe, status, remark, method, signature) VALUES(#{name}, #{url}, #{body}, #{module}, #{chinese}, #{shouldbe}, #{status}, #{remark}, #{method}, #{signature})")
    int addCases(TestCaseEntity testCaseEntity);

    @Delete("DELETE from test_case_entity where id = #{id}")
    int deleteCases(int caseID);

    @Select("SELECT * from test_case_entity where module = #{module}")
    List<TestCaseEntity> findCasesByModule(@Param("module") String module);

    @Select("SELECT remark from test_case_entity where id = #{id}")
    String getCaseRemark(int caseID);

    @Select("SELECT * from test_case_entity order by #{sortName} #{sortOrder}")
    List<TestCaseEntity> findAllCasesOrderBy(@Param("sortName") String sortName, @Param("sortOrder") String sortOrder);



    @Select("SELECT * from table_ServerManage")
    List<ServerEntity> findAllServer();

    @Select("SELECT * from table_ServerManage where Leader = #{Leader}")
    List<ServerEntity> findServerByLeader(@Param("Leader") String Leader);

    @Select("SELECT * from table_ServerManage where Leader like #{Leader} and Platform like  #{Platform} and ServerName like #{ServerName}")
    List<ServerEntity> findServerByLike(@Param("Leader") String Leader,@Param("Platform") String Platform,@Param("ServerName") String ServerName);

//    @Select("SELECT * from table_ServerManage where ServerName = #{ServerName}")
//    List<ServerEntity> findServerByServerName(@Param("ServerName") String ServerName);
//
//    @Select("SELECT * from table_ServerManage where Platform like  #{Platform}")
//    List<ServerEntity> findServerByPlatform(@Param("Platform") String Platform);
//
//    @Select("SELECT Count(*) AS Num from table_ServerManage where ApiName = #{ApiName}")
//    int findCountByServerName(@Param("ApiName") String ApiName);
//
//    @Insert("INSERT into table_ServerManage (ModuleName, ServerName, Description, Leader, ApiName, Platform) VALUES(#{ModuleName}, #{ServerName}, #{Description}, #{Leader}, #{ApiName}, #{Platform})")
//    int addServer(ServerEntity serverEntity);

}
